package com.cybertron.ironhide.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cybertron.ironhide.search.domain.PriceAlert;
import com.cybertron.ironhide.search.domain.Product;
import com.cybertron.ironhide.search.service.PriceAlertService;
import com.cybertron.ironhide.search.service.ProductService;

@Controller
@RequestMapping("/alert")
public class PriceAlertController {

	@Autowired(required = false)
	private ProductService productService;

	@Autowired(required = false)
	private PriceAlertService priceAlertService;

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public String get(@PathVariable("id") String id, Model model) {
		Product product = productService.selectByPrimaryKey(id);
		model.addAttribute("product", product);
		return "price_alert";
	}

	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	public String add(PriceAlert alert) {
		priceAlertService.insertSelective(alert);
		return "success";
	}
}
